import React from 'react'
import { Route, Redirect } from 'react-router-dom'
import tool from '../../utils/commonFuc'

// 判断是否从同一菜单过来
let token = tool.getUrlQuery('token') || sessionStorage.getItem('token')
let isAllMenu = tool.getUrlQuery('isAllMenu')
if(token){
    sessionStorage.setItem('token',token)
}
if(isAllMenu || sessionStorage.getItem('isAllMenu')){
    sessionStorage.setItem('isAllMenu','true')
}
const PrivateRoute = ({component: Component, ...rest}) => {   
  return (<Route {...rest} render={(props) => {
    return(    
      token
      ? <Component  />
      : <Redirect to={{
        pathname: '/login',
        state: {from: props.location}
      }}/>
  )}}/>)
}

export default PrivateRoute